package dfbz.demo03_数组;

public class Test03 {
    public static void main(String[] args) {
        int[] arr = new int[]{1, 2, 3, 4, 5, 6, 7, 9};
        int[] newArr=reverse(arr);
        printArr(newArr);
    }
    //反转方法
    public static int[] reverse(int[] arr){
        for (int i = 0; i < arr.length / 2; i++) {
            int temp = arr[i];
            arr[i] = arr[arr.length - 1 - i];
            arr[arr.length - 1 - i] = temp;
        }
        return arr;
    }
    //打印格式
        public static void printArr(int[]arr){
            System.out.print("[");
            for (int i = 0; i <arr.length ; i++) {
                if(i==arr.length-1){
                    System.out.print(arr[i]);
                }else {
                    System.out.print(arr[i]+",");
                }
        }
            System.out.println("]");
    }
}
